<template>
  <el-cascader
    :value="value"
    separator="|"
    :props="defaultProps"
    :options="options"
    @change="handleChange"
  />
</template>

<script>
import { getDepartment } from '@/api/department'
import { arr2tree } from '@/utils/index'
export default {
  props: {
    value: {
      type: Number,
      required: true
    }
  },
  data() {
    return {
      defaultProps: {
        value: 'id',
        label: 'name',
        emitPath: false
      },
      //   value: [],
      options: []
    }
  },
  created() {
    this.get()
  },
  methods: {
    async get() {
      const res = await getDepartment()
      this.options = arr2tree(res.data, 0)
    },
    handleChange(value) {
    //
      // const id = value[value.length - 1]
      this.$emit('input', value)
    }
  }
}
</script>

<style>

</style>
